package com.fish.yssb.wave;

import android.util.Log;

import java.util.ArrayList;
import java.util.HashMap;

import static com.fish.yssb.wave.WaveConsts.isShowLog;


public class WaveInfoJX {



    private static WaveInfo waveInfo;
    public static WaveInfo parseData(String [] arg)
    {
        waveInfo = new WaveInfo();
        waveInfo.mnlPassList = new HashMap<>();
        waveInfo.szlPassList = new HashMap<>();
        if(arg.length>0) {
            parseSubData1(arg[0].split(","));
        }
        if(arg.length>1) {
            parseSubData2(arg[1].split(","));
        }

        for(int i=0;i<waveInfo.mnlNum;i++)
        {
            if(arg.length>(2+i))
            {
                parseSubData3_0(arg[2+i].split(","),0);
            }
        }

        for(int i=0;i<waveInfo.szlNum;i++)
        {
            if(arg.length>(2+waveInfo.mnlNum+i))
            {
                parseSubData3_1(arg[2+waveInfo.mnlNum+i].split(","),1);
            }

        }



        return  waveInfo;
    }

    public  static void parseSubData2(String [] arg)
    {
        int num =0;
        if(arg.length>0)
        {
            try{
                num = Integer.parseInt(arg[0]);
            }catch (Exception ex)
            {
                ex.printStackTrace();
            }
            waveInfo.totalNum = num;
            if(isShowLog)
            {
                Log.e("====waveInfo","waveInfo.totalNum:"+waveInfo.totalNum);
            }
        }
        if(arg.length>1)
        {
            try{
                num = Integer.parseInt(arg[1].substring(0,arg[1].length()-1));
            }catch (Exception ex)
            {
                ex.printStackTrace();
            }
            waveInfo.mnlNum = num;
            if(isShowLog)
            {
                Log.e("====waveInfo","waveInfo.mnlNum:"+waveInfo.mnlNum);
            }
        }
        if(arg.length>2)
        {
            try{
                num = Integer.parseInt(arg[2].substring(0,arg[2].length()-1));
            }catch (Exception ex)
            {
                ex.printStackTrace();
            }
            waveInfo.szlNum = num;
            if(isShowLog)
            {
                Log.e("====waveInfo","waveInfo.szlNum:"+waveInfo.szlNum);
            }
        }
    }

    public  static void parseSubData3_0(String [] arg,int type)
    {
            PassInfo info = new PassInfo();

        if(arg.length>0)
        {
            info.passNo = arg[0];
            if(isShowLog)
            {
                Log.e("====waveInfo PassInfo","PassInfo.num:"+info.passNo);
            }
        }

        if(arg.length>1)
        {
            info.passName = arg[1];
            if(isShowLog)
            {
                Log.e("====waveInfo PassInfo","PassInfo.passName:"+info.passName);
            }
        }

        if(arg.length>2)
        {
            info.phase = arg[2];
            if(isShowLog)
            {
                Log.e("====waveInfo PassInfo","PassInfo.phase:"+info.phase);
            }
        }
        if(arg.length>3)
        {
            info.device = arg[3];
            if(isShowLog)
            {
                Log.e("====waveInfo PassInfo","PassInfo.device:"+info.device);
            }
        }

        if(arg.length>4)
        {
            info.unit = arg[4];
            if(isShowLog)
            {
                Log.e("====waveInfo PassInfo","PassInfo.unit:"+info.unit);
            }
        }

        if(arg.length>5)
        {
            String paraA = arg[5];
            float f_a = 0.00f;

            try {
                f_a = Float.parseFloat(paraA);
            }catch (Exception ex)
            {
                ex.printStackTrace();
            }
            info.paraA = f_a;
            if(isShowLog)
            {
                Log.e("====waveInfo PassInfo","PassInfo.f_a:"+info.paraA);
            }
        }
        if(arg.length>6)
        {
            String paraB = arg[6];
            float f_b = 0.00f;

            try {
                f_b = Float.parseFloat(paraB);
            }catch (Exception ex)
            {
                ex.printStackTrace();
            }
            info.paraB = f_b;
            if(isShowLog)
            {
                Log.e("====waveInfo PassInfo","PassInfo.f_b:"+info.paraB);
            }
        }

        waveInfo.mnlPassList.put(info.passNo,info);
        waveInfo.szlPassList = new HashMap<>();

    }
    public  static void parseSubData3_1(String [] arg,int type)
    {
        PassInfo info = new PassInfo();
        if(arg.length>0)
        {
            info.passNo = arg[0];
            if(isShowLog)
            {
                Log.e("====waveInfo PassInfo","PassInfo.num:"+info.passNo);
            }
        }

        if(arg.length>1)
        {
            info.passName = arg[1];
            if(isShowLog)
            {
                Log.e("====waveInfo PassInfo","PassInfo.passName:"+info.passName);
            }
        }
        waveInfo.szlPassList.put(info.passNo,info);

    }
    public static void parseSubData1(String [] arg)
    {
        if(arg.length>0)
        {
            waveInfo.station = arg[0];
            if(isShowLog)
            {
                Log.e("====waveInfo","waveInfo.station:"+waveInfo.station);
            }
        }
        if(arg.length>1)
        {
            waveInfo.quipNo = arg[1];
            if(isShowLog)
            {
                Log.e("====waveInfo","waveInfo.quipNo:"+waveInfo.quipNo);
            }
        }
        if(arg.length>2)
        {
            waveInfo.year = arg[2];
            if(isShowLog)
            {
                Log.e("====waveInfo","waveInfo.year:"+waveInfo.year);
            }
        }


    }

}